home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Sound Editor / Source / SoundEditorObj.cpp < prev    next >
Encoding:
Text File  |  1995-12-11  |  4.8 KB  |  211 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SoundEditorObj.cpp
  3.  
  4.     Contains:    EditorPropAccessor class implementation.
  5.  
  6.     Owned by:    Andrey Dolgachev
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- SoundEditor Includes --
  28.  
  29. #ifndef _SOUNDEDITOROBJ_
  30. #include "SoundEditorObj.h"
  31. #endif
  32.  
  33. #ifndef _SOUNDEDITORDEF_
  34. #include "SoundEditorDef.h"
  35. #endif
  36.  
  37. #ifndef _SOUNDEDITOR_
  38. #include "SoundEditor.h"
  39. #endif
  40.  
  41. // -- OpenDoc Includes --
  42.  
  43. #ifndef __ASREGISTRY__
  44. #include <ASRegistry.h>
  45. #endif 
  46.  
  47. // --- Macintosh Includes ---
  48.  
  49. #ifndef    __SOUNDINPUT__
  50. #include <SoundInput.h>
  51. #endif
  52.  
  53. #pragma segment SoundEditorObjectAccessors
  54.  
  55. //==============================================================================
  56. // EditorPropAccessor
  57. //==============================================================================
  58.  
  59. //------------------------------------------------------------------------------
  60. // EditorPropAccessor::EditorPropAccessor
  61. //------------------------------------------------------------------------------
  62.  
  63. EditorPropAccessor::EditorPropAccessor(DescType property, SoundEditor* part)
  64. {
  65.     fProperty = property;
  66.     fPart = part;
  67. }
  68.  
  69. //------------------------------------------------------------------------------
  70. // EditorPropAccessor::SetData
  71. //------------------------------------------------------------------------------
  72.  
  73. void EditorPropAccessor::SetData(AEDesc* data)
  74. {
  75.     // Sound Editor only supports setting one property: recording quality
  76.     switch(fProperty)
  77.     {
  78.         // If the specified property is this quality, then get at the specified
  79.         // quality from the AEDesc, and call the SetRecordingQuality method of
  80.         // the SoundEditor class in order to set the quality.
  81.         case pQuality:
  82.         {
  83.             DescType        theQual;
  84.             
  85.             theQual = **(DescType**)data->dataHandle;
  86.             switch (theQual) 
  87.             {
  88.                 case kGoodQuality:
  89.                     fPart->SetRecordingQuality( siGoodQuality );
  90.                     break;
  91.                 
  92.                 case kBetterQuality:
  93.                     fPart->SetRecordingQuality( siBetterQuality );
  94.                     break;
  95.                 
  96.                 case kBestQuality:
  97.                     fPart->SetRecordingQuality( siBestQuality );
  98.                     break;
  99.                 
  100.                 default:
  101.                     THROW(paramErr);
  102.             }
  103.             break;
  104.         }
  105.  
  106.         default:
  107.             THROW(errAENoSuchObject);
  108.             break;        
  109.     }
  110. }    
  111.  
  112. //------------------------------------------------------------------------------
  113. // EditorPropAccessor::GetData
  114. //------------------------------------------------------------------------------
  115.  
  116. void EditorPropAccessor::GetData(AEDesc* objectData)
  117. {
  118.     // Sound Editor supports getting six properties.
  119.     // For each property, the appropriate method of the SoundEditor class is called
  120.     // in order to find out the state of the property, then the value is packaged into
  121.     // an AEDesc used to carry the information.
  122.     switch(fProperty)
  123.     {
  124.         case pState:
  125.         {
  126.             DescType theState;
  127.             
  128.             if ( fPart->SoundPaused() )            
  129.             {
  130.                 if ( fPart->SoundRecording() )
  131.                     theState = kPauseRecordState;            
  132.                 else if ( fPart->SoundPlaying() )
  133.                     theState = kPausePlayState;
  134.                 else
  135.                     theState = kStopState;                
  136.             }
  137.             else
  138.             {
  139.                 if ( fPart->SoundRecording() )
  140.                     theState = kRecordState;            
  141.                 else if ( fPart->SoundPlaying() )
  142.                     theState = kPlayState;
  143.                 else
  144.                     theState = kStopState;                
  145.             }
  146.  
  147.             THROW_IF_ERROR(AECreateDesc(typeEnumerated, (Ptr) &theState, sizeof(theState), 
  148.                                         objectData));
  149.             break;
  150.         }
  151.  
  152.         case pQuality:
  153.         {
  154.             DescType theQual = (DescType) fPart->GetRecordingQuality();
  155.             
  156.             THROW_IF_ERROR(AECreateDesc(typeEnumerated, (Ptr) &theQual, sizeof(theQual), 
  157.                                         objectData));
  158.             break;
  159.         }
  160.         
  161.         case pCurrentTime:
  162.         {
  163.             long theTime;
  164.             
  165.             theTime = (long) fPart->GetCurrentTime();    
  166.                     
  167.             THROW_IF_ERROR(AECreateDesc(typeLongInteger, (Ptr) &theTime, sizeof(theTime), 
  168.                                         objectData));
  169.             break;
  170.         }
  171.  
  172.         case pMaxTime:
  173.         {
  174.             long theTime = (long) fPart->GetMaxTime();    
  175.                     
  176.             THROW_IF_ERROR(AECreateDesc(typeLongInteger, (Ptr) &theTime, sizeof(theTime), 
  177.                                         objectData));
  178.             break;
  179.         }
  180.  
  181.         case pLength:
  182.         {
  183.             long theTime = (long) fPart->GetRecordedTime();    
  184.                     
  185.             THROW_IF_ERROR(AECreateDesc(typeLongInteger, (Ptr) &theTime, sizeof(theTime), 
  186.                                         objectData));
  187.             break;
  188.         }
  189.  
  190.         case pSndQuality:
  191.         {
  192.             DescType theQual = kUnknownQuality;
  193.             OSType odQual;
  194.             
  195.             if ( fPart->GetSoundQuality(&odQual) )
  196.                 theQual = (DescType) odQual;
  197.             
  198.             THROW_IF_ERROR(AECreateDesc(typeEnumerated, (Ptr) &theQual, sizeof(theQual), 
  199.                                         objectData));
  200.             break;
  201.         }
  202.  
  203.         default:
  204.             THROW(errAENoSuchObject);
  205.             break;
  206.     }
  207. }
  208.  
  209.  
  210.  
  211.